package com.cskaoyan.market.controller;

import com.cskaoyan.market.bo.WxCartSubmitBo;
import com.cskaoyan.market.bo.WxCommentBo;
import com.cskaoyan.market.db.domain.MarketOrderGoods;
import com.cskaoyan.market.service.WxCommentService;
import com.cskaoyan.market.service.WxOrderService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    WxOrderService wxOrderService;

    @Autowired
    WxCommentService wxCommentService;

    @PostMapping("comment")
    public Object comment(@RequestBody WxCommentBo wxCommentBo) {
        // 处理业务逻辑
        wxCommentService.create(wxCommentBo);
        // 返回响应
        return ResponseUtil.ok();
    }

    @GetMapping("list")
    public Object list(Integer showType, Integer page, Integer limit) {
        // 处理业务逻辑
        Object object = wxOrderService.list(showType, page, limit);
        // 返回响应
        return object;
    }

    @GetMapping("detail")
    public Object detail(Integer orderId) {
        // 处理业务逻辑
        Map<String, Object> data = wxOrderService.detail(orderId);
        // 返回响应
        return ResponseUtil.ok(data);
    }

    @PostMapping("cancel")
    public Object cancel(@RequestBody Map map) {
        // 获取请求参数
        Integer orderId = (Integer) map.get("orderId");
        // 处理业务逻辑
        wxOrderService.cancel(orderId);
        // 返回响应
        return ResponseUtil.ok();
    }

    @PostMapping("refund")
    public Object refund(@RequestBody Map map) {
        // 获取请求参数
        Integer orderId = (Integer) map.get("orderId");
        // 处理业务逻辑
        wxOrderService.refund(orderId);
        // 返回响应
        return ResponseUtil.ok();
    }

    @PostMapping("delete")
    public Object delete(@RequestBody Map map) {
        // 获取请求参数
        Integer orderId = (Integer) map.get("orderId");
        // 处理业务逻辑
        wxOrderService.delete(orderId);
        // 返回响应
        return ResponseUtil.ok();
    }

    // 确认收货
    @PostMapping("confirm")
    public Object confirm(@RequestBody Map map) {
        // 获取请求参数
        Integer orderId = (Integer) map.get("orderId");
        // 处理业务逻辑
        wxOrderService.confirm(orderId);
        // 返回响应
        return ResponseUtil.ok();
    }

    // 评价入口
    @GetMapping("goods")
    public Object goods(Integer orderId, Integer goodsId) {
        // 处理业务逻辑
        MarketOrderGoods goods = wxOrderService.getGoods(orderId, goodsId);
        return ResponseUtil.ok(goods);
    }

    // 付款
    @PostMapping("prepay")
    public Object prepay(@RequestBody Map map) {
        // 获取请求参数
        Integer orderId = (Integer) map.get("orderId");
        // 处理业务逻辑
        wxOrderService.prepay(orderId);
        // 返回响应
        return ResponseUtil.ok();
    }

    // 提交订单
    @PostMapping("submit")
    public Object submit(@RequestBody WxCartSubmitBo wxCartSubmitBo) {
        // 处理业务逻辑
        Integer orderId = wxOrderService.submit(wxCartSubmitBo);
        // 返回响应
        Map<String, Object> data = new HashMap<>();
        data.put("orderId", orderId);
        data.put("grouponLinkId", wxCartSubmitBo.getGrouponLinkId());
        return ResponseUtil.ok(data);
    }
}
